/*
 * Copyright 2008 Max Kugland
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.splink.asbeangen;

import org.splink.asbeangen.parser.Parser;
import org.splink.asbeangen.templates.AS3TemplateFactory;

/**
 * @author maxmc
 */
public class Application {
	// TODO add flash Date object
	// TODO optional type for content nodes, currently only String is allowed
	// TODO fp10 flag -> Vector instead of Array
	public static void main(String[] args) {
		new Application(args);
	}

	public Application(String[] args) {
		String srcPath = "some.dtd";
		String targetPath = "some/path/to/src";
		String basePackage = "someBasePackageName";
		String gettersType = Const.GETTERS_TYPE_IMPLICIT;

		if (args.length >= 3) {
			srcPath = args[0];
			targetPath = args[1];

			if (args[2].indexOf(".") != -1) {
				basePackage = args[2].substring(0, args[2].lastIndexOf("."));
			} else {
				basePackage = args[2];
			}

		} else {
			System.out
					.println("arguments missing. using default values instead.\r\n\r\n"
							+ "arguments are:\r\n"
							+ "'srcpath' the path of the DTD\r\n"
							+ "'targetpath' the path in which the result is stored\r\n"
							+ "'basepackagename' the name of the folder which will be created within targetpath in which the generated classes are stored\r\n"
							+ "'getterstype' the type of getters to be used. Options are 'implicit-getters' or 'explicit-getters'\r\n\r\n"
							+ "'toxml' if toxml is present each data class gets a toXml method\r\n"
							+ "examplary arguments for the eclipse-external tools would be:\r\n"
							+ "'${resource_loc} ${project_loc}\\classes data.${resource_name} implicit-getters toxml'");
		}

		if (args.length > 3) {
			if (args[3].equals(Const.GETTERS_TYPE_EXPLICIT) || args[3].equals(Const.GETTERS_TYPE_IMPLICIT)) {
				gettersType = args[3];
			}
		}
		boolean toxml = false;
		if (args.length > 4 && args[4].equals("toxml")) {
			toxml = true;
		}

		String interfacePackage = basePackage + ".interfaces";
		new Parser(srcPath, targetPath, basePackage, new AS3TemplateFactory(interfacePackage, gettersType, toxml));
	}
}
